<?php
$connect = mysqli_connect("localhost","ip","ipipip");
mysqli_select_db($connect,"ip");
$n = $_GET['n'];
if (!$n) {
	$n = 0;
}
$file_contents = file('data/' . ($n + 1) . '.sql');
foreach($file_contents as $line){
	$str = explode('|', $line);
	$str1 = explode('.', $str[0]);
	$ip1 = $str1[0] * 255 * 255 * 255 + $str1[1] * 255 * 255 + $str1[2] * 255 + $str1[3];
	$str2 = explode('.', $str[1]);
	$ip2 = $str2[0] * 255 * 255 * 255 + $str2[1] * 255 * 255 + $str2[2] * 255 + $str2[3];
	$str = str_replace('|0', '|', $line);
	$str = explode('|', $str);
	$str3 = str_replace('  ', ' ', $str[2] . ' ' . $str[3] . ' ' . $str[4] . ' ' . $str[5] . ' ' . $str[6]);
	$str3 = str_replace('  ', ' ', $str3);
	mysqli_query($connect, 'insert into ip(ip1,ip2,address) values("' . $ip1 . '","' . $ip2 . '","' . $str3 . '")');
}
header('Content-type:text/html;charset=utf-8');
echo '<meta http-equiv="refresh" content="1;url=2.php?n=' . ($n + 1) . '">';